package com.wiyun.engine.skeleton;

import com.wiyun.engine.nodes.Director;
import com.wiyun.engine.nodes.Layer;
import com.wiyun.engine.nodes.Menu;
import com.wiyun.engine.nodes.MenuItemLabel;
import com.wiyun.engine.nodes.Scene;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.opengl.Texture2D; 
import com.wiyun.engine.transitions.CrossFadeTransition;
import com.wiyun.engine.transitions.TransitionScene;

public class MenuLayer extends Layer {

	public MenuLayer() {
		CreateBackground();
		CreateMenuItems();
	}

	public MenuLayer(int pointer) {
		super(pointer);
		// TODO Auto-generated constructor stub
	}
	
	public void CreateBackground()
	{
		Texture2D menubgTexture=Texture2D.makeJPG(R.drawable.menu_bg);
		menubgTexture.autoRelease();
		Sprite menubgSprite = Sprite.make(menubgTexture);
		menubgSprite.autoRelease();
		menubgSprite.setPosition(menubgSprite.getWidth()/2, menubgSprite.getHeight()/2);
		this.addChild(menubgSprite);
	}
	
	public void CreateMenuItems()
	{
		MenuItemLabel startMenuItem = MenuItemLabel.make("开始", this, "DisplayCardPanel");
		MenuItemLabel rankMenuItem = MenuItemLabel.make("排行榜");
		MenuItemLabel quitMenuItem = MenuItemLabel.make("退出");
		Menu menu=Menu.make(startMenuItem, rankMenuItem, quitMenuItem);
		menu.autoRelease();
		menu.alignItemsVertically();
		this.addChild(menu);
	}
	
	public void DisplayCardPanel()
	{
		Scene cardScene = Scene.make();
		cardScene.addChild(new CardPanelLayer());
		cardScene.autoRelease();
		Director.getInstance().replaceScene(getTransition(cardScene));
	}
	
	protected TransitionScene getTransition(Scene scene) {
		return (TransitionScene)CrossFadeTransition.make(2, scene).autoRelease();
    }

}
